<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>

async_test(function(t) {
    var script = 'no-such-worker';
    navigator.serviceWorker.register(script, { scope: script })
      .then(function() {
          assert_unreached('register() should fail');
        }, function(e) {
          assert_throws_js(
            TypeError, function() { throw e; },
            'register() on local file should fail');
          assert_equals(
            e.message,
            'Failed to register a ServiceWorker: The URL protocol of the ' +
            'current origin (\'file://\') is not supported.',
            'register() should fail due to unsupported URL protocol');
          t.done();
        })
      .catch(t.step_func(function(e) {
          assert_unreached(e);
          t.done();
        }));
}, 'Calling register() on local file');

async_test(function(t) {
    navigator.serviceWorker.getRegistration()
      .then(function() {
          assert_unreached('getRegistration() should fail')
        }, function(e) {
          assert_throws_dom(
            'SecurityError', function() { throw e; },
            'getRegistration() on local file should fail');
          assert_equals(
            e.message,
            'Failed to get a ServiceWorkerRegistration: The URL protocol of ' +
            'the current origin (\'file://\') is not supported.',
            'getRegistration() should fail due to unsupported URL protocol');
          t.done();
        })
      .catch(t.step_func(function(e) {
          assert_unreached(e);
          t.done();
        }));
}, 'Calling getRegistration() on local file');

</script>
